﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace Kotonoha.Server.Plugins {
    public class AttributedClassLoader {
        private readonly Type marker;

        public AttributedClassLoader(Type marker) {
            this.marker = marker;
        }

        public IEnumerable<Type> load(string fname) {
            Assembly loaded = Assembly.LoadFrom(fname);
            foreach(Type type in loaded.GetTypes()) {
                object[] attributes = type.GetCustomAttributes(marker, false);
                if (attributes.Length != 0) {
                    yield return type;
                }
            }
        }
    }
}
